import React, { PureComponent } from 'react';

import { Tree } from 'antd';

class Index extends PureComponent{

    render(){
        return(
            <Tree 
                {...this.props}
            >
                {this.renderTreeNode(this.props.data)}
            </Tree>
        )
    }

    renderTreeNode = (data)=>{
        return data.map((item)=>{
            if(item.children===undefined || item.children===[] || item.children==null || item.children==="" || item.children.length<1){
                return (
                    <Tree.TreeNode
                        key={item.key}
                        title={item.title}
                    />
                );
            }else{
                return(
                    <Tree.TreeNode 
                        key={item.key}
                        title={item.title}
                        selectable={false}
                        disabled = {true}
                    >
                        {this.renderTreeNode(item.children)}
                    </Tree.TreeNode>
                )
            }
        })
    }
}

export default Index;